layui.use(function () {
	var layer = layui.layer;
	var util = layui.util;
	layer.photos({
		photos: '.problem .item .txt',
		anim: 5
	});
	layui.use(function () {
		layui.code({
			elem: '.code-demo'
		});
	});
});

var interval = player = '';
onCCH5PlayerLoaded();
function onCCH5PlayerLoaded() {
	player = window.createCCH5Player({
		'vid': $(".video-box").data("vid"),
		'siteid': '2CF6808DAEF7DA69',
		'mediatype':1,
		'autoStart': false,
		'width': "100%",
		'height': '100%',
		'teaserId': $(".video-box").data("cast"),
		'parentNode': document.getElementById('player')
	});
}
function on_CCH5player_ready() {
	const time = Number($(".video-box").data("record"));
	time && player.jumpToTime(time);
}
function on_CCH5player_play() {
	interval = setInterval("render()",5000);
	addRecord(player.getPosition(),1)
}
function on_CCH5player_pause() {
	clearInterval(interval);
}
function on_CCH5player_ended() {
	addRecord(player.getPosition(),1);
	clearInterval(interval);
	console.log(player.getPosition());
	$.ajax({
		data:{id: $(".video-box").data("id"),time: Math.floor(player.getPosition())},
		type:'post',
		url: '/index/record/end',
		success: function(){}
	});
}
function render(){
	if(player != undefined && player.getPosition() != undefined){
		var sec2 = player.getPosition();
		if(sec2 != 0){addRecord(sec2,5)}
	}
}
function addRecord(a, d) {
	a =  Math.floor(a);
	$.ajax({
		data: {id: $(".video-box").data("id"),time: a, record: d, total: Math.floor(player.getDuration())},
		type: "post",
		url: "/index/record/add",
		success: function (c) {}
	});
}